Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: support of custom annotation loader #206

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

besir
Copy link
Contributor

@besir besir commented Feb 1, 2024

With this function we can added custom AnnotationLoader.

We use it for frequently used query params in request e.g.: filtering, sorting.

In our case we can use this:

	#[Path("/")]
	#[Method("GET")]
	#[Tag(name: '@authenticated', value: 'Internal')]
	#[RequestQuery(entity: UserListFilter::class)]
	#[Response(description: 'User exists', code: "200", entity: UserInfoCollection::class)]
	#[Response(description: 'User not found', code: "404")]
	#[Response(description: 'Invalid User ID', code: "400")]
	#[Response(description: 'unexpected error', code: 'default')]
	#[OpenApi("
		summary: Get users
		operationId: getUsers
		security:
			- BearerAuthInternal: []
		parameters:
			- name: 'userIds[]'
				in: query
				required: false
				description: List of required user IDs to receive
				style: form
				schema:
					type: array
					items:
						type: string
						format: uuid
		responses:
			'200':
				description: Return user info with KYC data if exists by user ID
				content:
					application/json:
						example:
	")]
	public function getUsers(ApiRequest $request, ApiResponse $response): ApiResponse
	{
		$filters = UserListFilter::factory($request, [
			'limit' => 25,
			'offset' => 0,
			'userIds' => [],
		]);
		$this->validator->validate($filters);

		$users = $this->userMediator->getUsers($filters);

		return $response->writeJsonBody($users->toArray());
	}

instead of this:

	#[Path("/")]
	#[Method("GET")]
	#[Tag(name: '@authenticated', value: 'Internal')]
	#[RequestParameter(name: 'userIds[]', type: 'string', in: 'query', required: false, description: '')]
	#[RequestParameter(name: 'limit', type: 'int', in: 'query', required: false, description: '')]
	#[RequestParameter(name: 'offset', type: 'int', in: 'query', required: false, description: '')]
	#[RequestParameter(name: 'userName', type: 'string', in: 'query', required: false, description: '')]
	#[RequestParameter(name: 'promoCode', type: 'string', in: 'query', required: false, description: '')]
	#[RequestParameter(name: 'email', type: 'string', in: 'query', required: false, description: '')]
	#[RequestParameter(name: 'status', type: 'string', in: 'query', required: false, description: 'new | active | del')]
	#[RequestParameter(name: 'lang', type: 'string', in: 'query', required: false, description: '')]
	#[Response(description: 'User exists', code: "200", entity: UserInfoCollection::class)]
	#[Response(description: 'User not found', code: "404")]
	#[Response(description: 'Invalid User ID', code: "400")]
	#[Response(description: 'unexpected error', code: 'default')]
	#[OpenApi("
		summary: Get users
		operationId: getUsers
		security:
			- BearerAuthInternal: []
		parameters:
			- name: 'userIds[]'
				in: query
				required: false
				description: List of required user IDs to receive
				style: form
				schema:
					type: array
					items:
						type: string
						format: uuid
		responses:
			'200':
				description: Return user info with KYC data if exists by user ID
				content:
					application/json:
						example:
	")]
	public function getUsers(ApiRequest $request, ApiResponse $response): ApiResponse
	{
		$filters = UserListFilter::factory($request, [
			'limit' => 25,
			'offset' => 0,
			'userIds' => [],
		]);
		$this->validator->validate($filters);

		$users = $this->userMediator->getUsers($filters);

		return $response->writeJsonBody($users->toArray());
	}

@besir besir force-pushed the custom-loader-support branch from cb675d3 to e4599fa Compare February 1, 2024 13:08
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (cb464d4) 90.61% compared to head (e9bb5a6) 90.55%.

Files Patch % Lines
src/Core/DI/Plugin/CoreSchemaPlugin.php 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #206      +/-   ##
==========================================
- Coverage   90.61%   90.55%   -0.07%     
==========================================
  Files         105      105              
  Lines        2408     2413       +5     
==========================================
+ Hits         2182     2185       +3     
- Misses        226      228       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@besir besir force-pushed the custom-loader-support branch 3 times, most recently from c41b0c2 to 6c4ed89 Compare February 1, 2024 14:25
@besir besir force-pushed the custom-loader-support branch from 6c4ed89 to e9bb5a6 Compare February 1, 2024 14:27
@f3l1x
Copy link
Member

f3l1x commented Feb 4, 2024

I like it, can you please provide little test for it with custom loader? Some dummy loader doing nothing.

@f3l1x f3l1x merged commit 816aa4f into contributte:master Feb 23, 2024
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants